package com.luxoft.dao;

import java.sql.*;

/**
 * Created by IntelliJ IDEA.
 * User: dkuzkin
 * Date: 6/30/11
 * Time: 10:16 AM
 * To change this template use File | Settings | File Templates.
 */
public class ConnectionPool {
    private final static String DRIVER_NAME = "oracle.jdbc.driver.OracleDriver";
    private static String url;
    private static Connection connection;
    private static boolean isConnected = false;


    private static boolean connect() {
        try {
            url = "jdbc:oracle:thin:@" + ConnectionInfo.getSERVER() + ":" + ConnectionInfo.getPORT() + ":" + ConnectionInfo.getSID();
            //System.out.println(url);
            Class.forName(DRIVER_NAME);
            connection = DriverManager.getConnection(url, ConnectionInfo.getUSERNAME(), ConnectionInfo.getPASSWORD());
            //System.out.println("connecting: " + url);
            isConnected = !connection.equals(null);
        } catch (ClassNotFoundException e) {
            System.out.println("ClassNotFoundException");
            isConnected = false;
        } catch (SQLException e) {
            System.out.println("SQLException\n" + e.getMessage());
            isConnected = false;
        }
        return isConnected;
    }

    public static Connection getConnection(){
        connect();
        return connection;
    }


}
